package com.linzx.markdown.dialog;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.ui.EditorTextField;
import com.linzx.markdown.entity.DataCenter;
import com.linzx.markdown.entity.NoteDate;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;

/**
 * @author avicomlin
 * @Description: 添加笔记
 * @date 2021/1/17
 */
public class AddNoteDialog extends DialogWrapper {
    public AddNoteDialog() {
        super(true);
        setTitle("标题");
        init();
    }

    private EditorTextField title;
    private EditorTextField context;

    @Nullable
    @Override
    protected JComponent createCenterPanel() {
        JPanel panel = new JPanel(new BorderLayout());
        //推荐使用这个
        title = new EditorTextField("title");
        context = new EditorTextField("context");

        //s设置输入框的宽高
        context.setPreferredSize(new Dimension(200,100));

        panel.add(title, BorderLayout.NORTH);
        panel.add(context, BorderLayout.CENTER);
        return panel;
    }

    @Override
    protected JComponent createSouthPanel() {
        JPanel panel = new JPanel();
        JButton button = new JButton("添加笔记");
        button.addActionListener(e -> {
            String fileType = DataCenter.FILE_NAME.substring(DataCenter.FILE_NAME.lastIndexOf(".")+1);
            NoteDate noteDate = new NoteDate(title.getText(), context.getText(), DataCenter.SELECT_TEXT,  DataCenter.FILE_NAME, fileType);
            DataCenter.LIST.add(noteDate);
            System.out.println(noteDate);
            DataCenter.TABLE_MODEL.addRow(DataCenter.convert(noteDate));
        });
        panel.add(button);
        return panel;
    }
}
